import { Toast } from "vant";
export default {
  components: {},
  props: {},
  data() {
    return {
        foot_type: 1,
        bottom_info: {},
        balance: 0,//余额
        point: 0,//总积分
        integral: 0,//兑换积分
        zhutui: 0,//直推奖
        gongxiang: 0,//共享奖
        guanli: 0,//管理奖
        zhuli: 0,//助力奖
        fuli: 0,//福利奖
        fenhong: 0,//分红
        loginshow: !1,
        jijin: 0,//基金
        tuanpin: 0,//团拼
        assetsObj: {},
        level_name: '',//正常会员（AB市场）等级
    };
  },
  activated() {
    
    this.firstlogin();
    this.bottom_info = JSON.parse(window.localStorage.getItem('yz_basic_info')).home.item.menus.page_info;
    var uid = localStorage.getItem("uid") ? localStorage.getItem("uid") : '';
    console.log(uid,'uid');
    if(uid != ''){
      console.log('用户已登录');
      this.getData();
      this.getuserinfo();
    }else {
       this.level_name == '';
    }
   
  },

  methods: {
    // 正常滑落会员信息
    async getuserinfo(){
        var that = this;
        var res = await $http.post("shijiahe.userinfo", { 
            uid: localStorage.getItem("uid") ? localStorage.getItem("uid") : localStorage.getItem("mid")
        })
        console.log(res.data,'用户信息');
        var obj = res.data;
        // var level_name = obj && obj.level_name ? obj.level_name : '营销代表';
       var res1 = await  $http.post("shijiahe.get_huiyuan_goods", { 
              uid: localStorage.getItem("uid") ? localStorage.getItem("uid") : ''
        })
        console.log(res1.data,'是否购买会员区商品');
        var obj1 = res1.data;
        if(obj1 > 0){
          if(obj && obj.level_name){
            that.level_name =  obj.level_name;
          }else {
            that.level_name = '营销代表';
          }
        }else {
          that.level_name = '';
        }
        // $http.post("shijiahe.userinfo", { 
        //     uid: localStorage.getItem("uid") ? localStorage.getItem("uid") : localStorage.getItem("mid")
        //     // uid: 133631
        // }).then(res => {
        //     if (res.result == 1) {
        //         var obj = res.data;
        //         that.level_name = obj && obj.level_name ? obj.level_name : '营销代表';
        //     }
            
        // });
    },
    // 获取会员是否够买会员区商品
    // getuserinfo(){
    //     var that = this;
    //     $http.post("shijiahe.get_huiyuan_goods", { 
    //         uid: localStorage.getItem("uid") ? localStorage.getItem("uid") : localStorage.getItem("mid")
    //         // uid: 133631
    //     }).then(res => {
    //         if (res.result == 1) {
    //             var obj = res.data;
    //             that.level_name = obj && obj.level_name ? obj.level_name : '营销代表';
    //         }
            
    //     });
    // },
    toZhuanhuan(){
      this.$router.push(this.fun.getUrl("member_transfer_integral"))
    },
    // 跳转到余额
    toBalance(){
        this.$router.push(this.fun.getUrl("balance"))
    },
    tozhuanhuanjifen(){
        this.$router.push(this.fun.getUrl("Integral_love"))
    },
    tojifenList(){
        this.$router.push(this.fun.getUrl("integrallist"))
    },
    toAssetsDetail(type){
        // wx.navigateTo({
        // url: '/packageJ/newPage/yueyuezhuan/yueyuezhuan',
        // })
        if(type == 'gongxiang' || type == 'fuli' || type == 'fenhong'){
          this.$router.push(this.fun.getUrl("assetsDetailOther", { title: type, point_mode: this.getPointMode(type) }))
        }else if(type == 'tuanpin'){
          this.$router.push(this.fun.getUrl("assetsDetailTuan", { title: type, point_mode: this.getPointMode(type), point: this.tuanpin}))
        }else {
          this.$router.push(this.fun.getUrl("assetsDetail", { title: type, point_mode: this.getPointMode(type) }))
        }
        
        
    },
    getPointMode(key) {
      // 动态拼接_code后缀的键名
      const codeKey = key + '_code';
      
      // 获取并返回值（如果键存在）
      if (this.assetsObj.hasOwnProperty(codeKey)) {
        return this.assetsObj[codeKey];
      } else {
        console.warn(`键 "${codeKey}" 不存在`);
        return null;
      }
    },
    getData(){
        var that = this;
        $http.post("shijiahe.my_asset", { 
            uid: localStorage.getItem("uid") ? localStorage.getItem("uid") : localStorage.getItem("mid")
        }).then(res => {
            if (res.result == 1) {
                var obj = res.data;
                console.log(res.data,'我的资产')
                that.assetsObj = obj;
                that.balance = obj.balance ? obj.balance : 0;//余额
                that.point = obj.point ? obj.point : 0;//总积分
                that.integral = obj.integral ? obj.integral : 0;//兑换积分
                that.zhutui = obj.zhutui ? obj.zhutui : 0;//直推奖
                that.gongxiang = obj.gongxiang ? obj.gongxiang : 0;//共享奖
                that.guanli = obj.guanli ? obj.guanli : 0;//管理奖
                that.zhuli = obj.zhuli ? obj.zhuli : 0;//助力奖
                that.fuli = obj.fuli ? obj.fuli : 0;//福利奖
                that.fenhong = obj.fenhong ? obj.fenhong : 0;//分红
                that.tuanpin = obj.tuanpin ? obj.tuanpin : 0;//团拼
            }
            
        });
    },
    firstlogin: function() {
        // var t = !1;
        // try {
        //     wx.getStorageSync("wx_token") ? (this.setData({
        //         loginshow: !1
        //     }), t = !1) : (this.setData({
        //         loginshow: !0
        //     }), t = !0);
        // } catch (e) {
        //     this.setData({
        //         loginshow: !0
        //     }), t = !0;
        // }
        // return t;
    },
    gotologin: function() {
    wx.navigateTo({
        url: "/pages/login/login"
    });
    },
    // 实名认证
    submit() {
      
      if (this.username == "") {
        Toast("请输入姓名");
        return;
      }
      if (this.cardno == "") {
        Toast("请输入身份证号");
        return;
      }
      var that = this;
      
      $http.post("TuWenhua.shiming", { 
        name: this.username, 
        idcard: this.cardno,
        uid: localStorage.getItem("uid") ? localStorage.getItem("uid") : localStorage.getItem("mid")
      }).then(res => {
        console.log(res,'实名认证');
        if (res.result == 0) {
          return this.$toast(res.msg);
        }
        this.$toast('认证成功');
        if(that.type == 1) {
          this.$router.push(this.fun.getUrl("home"));
        }else {
          this.$router.push(this.fun.getUrl("uploadAuthorization", { id: that.orderId }));
        }
        
      });
     
    }
  },
  components: {
      U_foot: () => import("../../../components/new_diy/foot.vue")
    }
};
